const express = require('express')
const router = express.Router()
const fs = require('fs')
const xlsx = require('node-xlsx')
router.get('/china/city', (req, res, next) => {
  const chinaCityXlsx = fs.readFileSync(`${__dirname}/chaina-city-list.xlsx`)
  const chinaCity = xlsx.parse(chinaCityXlsx)
  let city = chinaCity[0].data.map((v, i) => {
    if (i > 0 && v.length !== 0) {
      return {
        city_code: v[0],
        city_en: v[1],
        city_cn: v[2],
        country_code: v[3],
        country_en: v[4],
        country_cn: v[5],
        province_en: v[6],
        province_cn: v[7],
        parent_city_en: v[8],
        parent_city_cn: v[9],
        latitude: v[10],
        longitude: v[11]
      }
    }
  })
  res.json(city)
})
module.exports = router
